{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Final URL: https://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a&timestamp__1258=YqGO7KBKD5YKY5D%3DoDsq8dr8G89vxDkYB8eD\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.support import expected_conditions as EC\n",
    "\n",
    "# 创建一个 Chrome 浏览器实例\n",
    "driver = webdriver.Chrome()\n",
    "\n",
    "# 打开初始网页\n",
    "driver.get(\"https://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a&timestamp__1258=YqGO7KBKD5YKY5D%3DoDsq8dr8G89weDk8%2BzeD\")\n",
    "\n",
    "# 等待一定时间，确保页面加载完成\n",
    "# 这里可以根据实际情况调整等待时间\n",
    "wait = WebDriverWait(driver, 10)\n",
    "wait.until(EC.url_changes(\"https://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a&timestamp__1258=YqGO7KBKD5YKY5D%3DoDsq8dr8G89weDk8%2BzeD\"))\n",
    "\n",
    "# 获取最终的 URL\n",
    "final_url = driver.current_url\n",
    "\n",
    "# 打印最终的 URL\n",
    "print(\"Final URL:\", final_url)\n",
    "\n",
    "# 关闭浏览器\n",
    "driver.quit()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "ename": "TimeoutException",
     "evalue": "Message: \n",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTimeoutException\u001B[0m                          Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[18], line 51\u001B[0m\n\u001B[0;32m     48\u001B[0m \u001B[38;5;66;03m# 等待一定时间，确保页面加载完成\u001B[39;00m\n\u001B[0;32m     49\u001B[0m \u001B[38;5;66;03m# 这里可以根据实际情况调整等待时间\u001B[39;00m\n\u001B[0;32m     50\u001B[0m wait \u001B[38;5;241m=\u001B[39m WebDriverWait(driver, \u001B[38;5;241m10\u001B[39m)\n\u001B[1;32m---> 51\u001B[0m \u001B[43mwait\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43muntil\u001B[49m\u001B[43m(\u001B[49m\u001B[43mEC\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43murl_changes\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mhttps://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a&timestamp__1258=YqGO7KBKD5YKY5D\u001B[39;49m\u001B[38;5;124;43m%\u001B[39;49m\u001B[38;5;124;43m3DoDsq8dr8G89weDk8\u001B[39;49m\u001B[38;5;124;43m%\u001B[39;49m\u001B[38;5;124;43m2BzeD\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m     53\u001B[0m \u001B[38;5;66;03m# 获取最终的 URL\u001B[39;00m\n\u001B[0;32m     54\u001B[0m final_url \u001B[38;5;241m=\u001B[39m driver\u001B[38;5;241m.\u001B[39mcurrent_url\n",
      "File \u001B[1;32mE:\\Anaconda3\\lib\\site-packages\\selenium\\webdriver\\support\\wait.py:101\u001B[0m, in \u001B[0;36mWebDriverWait.until\u001B[1;34m(self, method, message)\u001B[0m\n\u001B[0;32m     99\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m time\u001B[38;5;241m.\u001B[39mmonotonic() \u001B[38;5;241m>\u001B[39m end_time:\n\u001B[0;32m    100\u001B[0m         \u001B[38;5;28;01mbreak\u001B[39;00m\n\u001B[1;32m--> 101\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m TimeoutException(message, screen, stacktrace)\n",
      "\u001B[1;31mTimeoutException\u001B[0m: Message: \n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.support import expected_conditions as EC\n",
    "from selenium.webdriver.chrome.options import Options\n",
    "\n",
    "# 创建一个 Chrome 浏览器实例\n",
    "chrome_options = Options()\n",
    "\n",
    "# 添加头部信息\n",
    "headers = {\n",
    "    \"Accept\": \"application/json, text/javascript, */*; q=0.01\",\n",
    "    \"Accept-Encoding\": \"gzip, deflate, br\",\n",
    "    \"Accept-Language\": \"zh-CN,zh;q=0.9\",\n",
    "    \"Connection\": \"keep-alive\",\n",
    "    \"Content-Length\": \"190\",\n",
    "    \"Content-Type\": \"application/x-www-form-urlencoded; charset=UTF-8\",\n",
    "    \"Host\": \"vapi.51job.com\",\n",
    "    \"Origin\": \"https://jobs.51job.com\",\n",
    "    \"Referer\": \"https://jobs.51job.com/\",\n",
    "    \"Sec-Fetch-Dest\": \"empty\",\n",
    "    \"Sec-Fetch-Mode\": \"cors\",\n",
    "    \"Sec-Fetch-Site\": \"same-site\",\n",
    "    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\",\n",
    "    \"account-id\": \"225393392\",\n",
    "    \"sec-ch-ua\": \"\\\"Google Chrome\\\";v=\\\"119\\\", \\\"Chromium\\\";v=\\\"119\\\", \\\"Not?A_Brand\\\";v=\\\"24\\\"\",\n",
    "    \"sec-ch-ua-mobile\": \"?0\",\n",
    "    \"sec-ch-ua-platform\": \"\\\"Windows\\\"\"\n",
    "}\n",
    "\n",
    "for key, value in headers.items():\n",
    "    chrome_options.add_argument(f'--header={key}:{value}')\n",
    "\n",
    "# 设置浏览器路径\n",
    "chrome_path = \"D:/chromedriver/chromedriver.exe\"\n",
    "\n",
    "# 添加路径到可执行文件\n",
    "# 指定 Chrome 浏览器路径\n",
    "chrome_options.binary_location = r'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'\n",
    "\n",
    "\n",
    "# 创建浏览器对象\n",
    "driver = webdriver.Chrome(options=chrome_options)\n",
    "\n",
    "# 打开初始网页\n",
    "driver.get(\"https://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a&timestamp__1258=YqGO7KBKD5YKY5D%3DoDsq8dr8G89weDk8%2BzeD\")\n",
    "\n",
    "# 等待一定时间，确保页面加载完成\n",
    "# 这里可以根据实际情况调整等待时间\n",
    "wait = WebDriverWait(driver, 10)\n",
    "wait.until(EC.url_changes(\"https://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a&timestamp__1258=YqGO7KBKD5YKY5D%3DoDsq8dr8G89weDk8%2BzeD\"))\n",
    "\n",
    "# 获取最终的 URL\n",
    "final_url = driver.current_url\n",
    "\n",
    "# 打印最终的 URL\n",
    "print(\"Final URL:\", final_url)\n",
    "\n",
    "# 关闭浏览器\n",
    "driver.quit()\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
